<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>student</title>
    <div th:include="../templates/aaacommon/basic::copy"></div>
</head>

<body>
<div class="layui-form contain ">
    <form class="layui-form layui-form-pane" th:action="@{{path}/student/save(path=${application.basePath}) }" method="post" name="edit_form" id="edit_form">
    	    <input type="hidden" id="id" name="id" th:value="${id}"/>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" placeholder="请输入姓名" class="layui-input" lay-verify="required"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="text" id="sex" name="sex" placeholder="请输入性别" class="layui-input" lay-verify="required"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" id="email" name="email" placeholder="请输入邮箱" class="layui-input" lay-verify="required"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" placeholder="请输入手机" class="layui-input" lay-verify="required"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-inline">
                    <input type="text" id="addr" name="addr" placeholder="请输入地址" class="layui-input" lay-verify="required"/>
                </div>
            </div>
    		<div class="layui-form-item">
    			<div class="layui-input-block">
    				<button hzz:show="key_save" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="save">保存</button>
    				<button class="layui-btn layui-btn-primary" id="close">关闭</button>
    			</div>
    		</div>
    	</form>
</div>


<script type="text/javascript">
    layui.use(['element', 'form', 'layer', 'web'], function () {
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        var web = layui.web;

        var contro_path = '/student';
        //…

        var id = $("#id").val();
        var obj = null;
        if (id != null && id != "") {
            var url = basePath + contro_path + "/searchDetail";
            web.ajax_sync(url, 'post', {id: id}, function (data) {
                obj = data.result;
                $("#name").val(obj.name);
                $("#sex").val(obj.sex);
                $("#email").val(obj.email);
                $("#phone").val(obj.phone);
                $("#addr").val(obj.addr);
                //$("#createtime").val(obj.createtime);
                form.render();
            });
        }

        //关闭当前弹出层
        $("#close").click(function () {
            var current_index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(current_index); //用父窗口的layer对象关闭当前弹出层
        });
        //保存
        form.on('submit(save)', function (data) {
            var url = basePath + contro_path + "/save";
            console.log(data.field);
            web.ajax(url, 'post', data.field, function (data) {
                layer.alert("保存成功", {
                    icon: 1
                }, function (index) {
                    layer.close(index);//关闭当前层

                    var current_index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(current_index); //用父窗口的layer对象关闭当前弹出层

                    parent.$("#query_data").click();
                });
            });
            return false;
        });

    });
</script>
</body>
</html>

